package com.woniuxy.controller;

import com.woniuxy.po.Mail;
import com.woniuxy.po.TopicMail;
import com.woniuxy.service.Producer;
import com.woniuxy.service.Publisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: 马宇航
 * @Do: RabbitMQ controller接口
 * @DateTime: 22/07/06/0006 下午 2:59
 * @Component: 成都蜗牛学苑
 **/
@Controller
public class RabbitMQController {
    @RequestMapping("/demo")
    public String iniPage() {
        return "demo";
    }

    //创建service连接 生产者接口
    @Autowired
    Producer producer;


    @RequestMapping(value = "/produce")
    @ResponseBody
    public void producerPublish(@ModelAttribute("mail") Mail mail) {
        producer.sendMail("pcqueue", mail);
    }

    @Autowired
    Publisher publisher;
    @RequestMapping(value = "/fanout")
    @ResponseBody
    public void fanout(@ModelAttribute("mail") Mail mail) {
        publisher.fanoutMail(mail);
    }
    @RequestMapping(value = "/direct")
    @ResponseBody
    public void direct(@ModelAttribute("mail") TopicMail topicMail) {
        publisher.directMail(topicMail);
    }
    //处理正常的消息，实现消息长度超过5个长度
    @RequestMapping(value = "/normaltopic")
    @ResponseBody
    public void longerThan5(@ModelAttribute("mail") Mail mail) {
        publisher.sendNormalQueue(mail);
    }
    //处理正常的消息，实现ttl消息过期
    @RequestMapping(value = "/ttltopic")
    @ResponseBody
    public void ttlMethod(@ModelAttribute("mail") Mail mail) {
        publisher.sendTtlQueue(mail);
    }
    // 延迟队列controller
    @RequestMapping(value = "/delaytopic")
    @ResponseBody
    public void delaytopic(@ModelAttribute("mail") TopicMail topicMail) {
        publisher.sendDelayMessage(topicMail);
    }

}